package cn.wsalix.observable.service.impl;

import java.util.Observable;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.wsalix.biz.entity.Article;
import cn.wsalix.biz.form.ArticleForm;
import cn.wsalix.biz.service.ArticleService;
import cn.wsalix.observable.service.ArtChangeService;
import cn.wsalix.user.service.AddressService;

@Service("artChangeService")
public class ArtChangeServiceImpl extends Observable implements ArtChangeService {
	protected Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private ArticleService articleService;
	@Autowired
	private AddressService addressService;
	private Article art;
	@PostConstruct
	public void init() {
		logger.info("==========init");
		addObserver(articleService);
	}

	@PreDestroy
	public void destroy() {
		logger.info("==========destroy");
	}
	@Transactional
	@Override
	public Article Change(ArticleForm form) {
		setChanged();
		notifyObservers(form);
		return art;
	}

	@Override
	public Article getArticle() {
		return art;
	}

	@Override
	public void setArticle(Article art) {
		this.art=art;
	}

}
